home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / d_d / caltech / inbound / mcm / mcmsplit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-22  |  8.0 KB  |  368 lines

  1. /* MCM  -  MultiUser Communications Manager
  2.  
  3.    Copyright (C) 1991,2 Michael Sawyer
  4.  
  5.    This code may be reproduced without charge provided that this
  6.    notice remains intact on all copies distributed.
  7.  
  8.    Any part of this code may be used in other programs provided that
  9.    some citation of this work is given.
  10. */
  11.  
  12. #include "mcm.h"
  13.  
  14. /* This is the split-screen support module.  It is actually two */
  15. /* modules in one; a Curses based routine, and a seperate Termcap */
  16. /* based routine.  They really shouldn't be as seperate as they are, */
  17. /* but I haven't had the chance to merge them yet... */
  18.  
  19. #ifdef CURSES
  20. /* The curses code is GONE! */
  21. #endif /* CURSES */
  22.  
  23. #ifdef TERMCAP
  24.  
  25. /* Strip padding from the capabilities */
  26. char *depad (textptr)
  27. char *textptr;
  28. {
  29.   int i;
  30.  
  31.   while ((isdigit(textptr[0]))||(textptr[0]=='*'))
  32.     textptr++;
  33.   return (textptr);
  34. }
  35.  
  36.  
  37. extern struct JOB job[NUMJOBS];
  38.  
  39. void splinit(id,termtype)
  40. int id;
  41. char *termtype;
  42. {
  43.   char glob[1024];
  44.   char message[256];
  45.   char *textptr;
  46.   char storage[1024];
  47.   char *area;
  48.   int i;
  49.  
  50.   for (i=0;i<1024;i++)
  51.     storage[i]=0;
  52.   if (!testjob(id))
  53.     return;
  54.   /* Set char-at-a-time mode */
  55.   write (job[id].fd,"\377\373\001\377\373\003",6);
  56.   if (tgetent(glob,termtype)!=1)
  57.   {
  58.     strcpy (message,"Could not open TERMCAP entry!");
  59.     goto OPENBAIL;
  60.   }
  61.   area=storage;
  62.   if ((textptr=tgetstr("al",&area))!=NULL)
  63.   {
  64.     textptr=depad(textptr);
  65.     strncpy(job[id].al,textptr,32);
  66.   }
  67.   else
  68.     job[id].al[0]=0;
  69.   if ((textptr=tgetstr("bc",&area))!=NULL)
  70.   {
  71.     textptr=depad(textptr);
  72.     strncpy(job[id].bc,textptr,32);
  73.   }
  74.   else
  75.     strcpy (job[id].bc,"\007");
  76.   if ((textptr=tgetstr("cd",&area))!=NULL)
  77.   {
  78.     textptr=depad(textptr);
  79.     strncpy(job[id].cd,textptr,32);
  80.   }
  81.   else
  82.     job[id].cd[0]=0;
  83.   if ((textptr=tgetstr("rs",&area))!=NULL)
  84.   {
  85.     textptr=depad(textptr);
  86.     strncpy(job[id].rs,textptr,32);
  87.   }
  88.   else
  89.     strcpy (job[id].rs," --- RESET TERMINAL NOW ---\r\n");
  90.   if ((textptr=tgetstr("ce",&area))!=NULL)
  91.   {
  92.     textptr=depad(textptr);
  93.     strncpy(job[id].ce,textptr,32);
  94.   }
  95.   else
  96.   {
  97.     strcpy (message,"Your terminal isn't smart enough to run split-screen!");
  98.     goto OPENBAIL;
  99.   }
  100.   if ((textptr=tgetstr("do",&area))!=NULL)
  101.   {
  102.     textptr=depad(textptr);
  103.     strncpy(job[id].xdo,textptr,32);
  104.   }
  105.   else
  106.   {
  107.     strcpy (message,"Your terminal isn't smart enough to run split-screen!");
  108.     goto OPENBAIL;
  109.   }
  110.   if ((textptr=tgetstr("sr",&area))!=NULL)
  111.   {
  112.     textptr=depad(textptr);
  113.     strncpy(job[id].sr,textptr,32);
  114.   }
  115.   else
  116.     job[id].sr[0]=0;
  117.   if ((textptr=tgetstr("cs",&area))!=NULL)
  118.   {
  119.     textptr=depad(textptr);
  120.     strncpy(job[id].cs,textptr,32);
  121.   }
  122.   else
  123.     job[id].cs[0]=0;
  124.   if ((textptr=tgetstr("cl",&area))!=NULL)
  125.   {
  126.     textptr=depad(textptr);
  127.     strncpy(job[id].cl,textptr,32);
  128.   }
  129.   else
  130.   {
  131.     strcpy (message,"Your terminal isn't smart enough to run split-screen!");
  132.     goto OPENBAIL;
  133.   }
  134.   if ((textptr=tgetstr("cm",&area))!=NULL)
  135.   {
  136.     textptr=depad(textptr);
  137.     strncpy (job[id].cm,textptr,32);
  138.   }
  139.   else
  140.   {
  141.     strcpy (message,"Your terminal isn't smart enough to run split-screen!");
  142.     goto OPENBAIL;    
  143.   }
  144.   if ((textptr=tgetstr("dc",&area))!=NULL)
  145.   {
  146.     textptr=depad(textptr);
  147.     strncpy(job[id].dc,textptr,32);
  148.   }
  149.   else
  150.     job[id].dc[0]=0;
  151.   if ((textptr=tgetstr("dl",&area))!=NULL)
  152.   {
  153.     textptr=depad(textptr);
  154.     strncpy(job[id].dl,textptr,32);
  155.   }
  156.   else
  157.     job[id].dl[0]=0;
  158.   if ((textptr=tgetstr("so",&area))!=NULL)
  159.   {
  160.     textptr=depad(textptr);
  161.     strncpy(job[id].so,textptr,32);
  162.   }
  163.   else
  164.     job[id].so[0]=0;
  165.   if ((textptr=tgetstr("se",&area))!=NULL)
  166.   {
  167.     textptr=depad(textptr);
  168.     strncpy(job[id].se,textptr,32);
  169.   }
  170.   else
  171.     job[id].se[0]=0;
  172.   if ((job[id].cs[0]==0)&&((job[id].dl[0]==0)||(job[id].al[0]==0)))
  173.   {
  174.     strcpy (message,"Your terminal isn't smart enough to run split-screen!");
  175.     goto OPENBAIL;    
  176.   }
  177.   job[id].co=tgetnum("co");
  178.   job[id].li=tgetnum("li");
  179.   strncpy(job[id].termtype,termtype,16);
  180.   textptr=tgoto(job[id].cm,0,job[id].li-4);
  181.   sprintf (message, "%s%s%s MCM Split-Screen mode (TERMCAP)  --- /T alone to return to normal mode %s\n\r",
  182.        job[id].cl,textptr,job[id].so,job[id].se);
  183.   write (job[id].fd,message,strlen(message));
  184.   strcpy (message,tgoto(job[id].cm,0,job[id].li-3));
  185.   write (job[id].fd,message,strlen(message));
  186.   return;
  187.  
  188. OPENBAIL:
  189.   write (job[id].fd,"\377\374\001\377\374\003",6);
  190.   job[id].termtype[0]=0;
  191.   tell (-1,id,"(sys)",message);
  192.   return;
  193. }
  194.  
  195. void splend(id)
  196. int id;
  197. {
  198.   char *textptr;
  199.  
  200.   if (job[id].cs[0]!=0)
  201.   {
  202.     textptr=tgoto (job[id].cs,127,0);
  203.     write (job[id].fd,textptr,strlen(textptr));
  204.   }
  205.   if (job[id].cl[0]!=0)
  206.   {
  207.     write (job[id].fd,job[id].cl,strlen(job[id].cl));
  208.   }
  209.   write (job[id].fd,job[id].rs,strlen(job[id].rs));
  210.   write (job[id].fd,"\027\377\374\001\377\374\003",7);
  211.   job[id].termtype[0]=0;
  212. }
  213.  
  214. void spltxout(id,text)
  215. int id;
  216. char *text;
  217. {
  218.   char *textptr;
  219.  
  220.   if (job[id].cs[0]!=0)
  221.   {
  222.     textptr=tgoto (job[id].cs,job[id].li-5,1);
  223.     write (job[id].fd,textptr,strlen(textptr));
  224.     textptr=tgoto (job[id].cm,0,job[id].li-5);
  225.     write (job[id].fd,textptr,strlen(textptr));
  226.     write (job[id].fd,text,strlen(text));
  227.     return;
  228.   }
  229.  
  230.   /* First, check to see if we can go to the top, and remove a line */
  231.   if ((job[id].dl[0]!=NULL)&&(job[id].al[0]!=0))
  232.   {
  233.     /* Now, we can do it the easy way! */
  234.     textptr=tgoto(job[id].cm,0,0);
  235.     write (job[id].fd,textptr,strlen(textptr));
  236.     write (job[id].fd,job[id].dl,strlen(job[id].dl));
  237.     textptr=tgoto(job[id].cm,0,job[id].li-5);
  238.     write (job[id].fd,textptr,strlen(textptr));
  239.     write (job[id].fd,job[id].al,strlen(job[id].al));
  240.     write (job[id].fd,text,strlen(text));
  241.     return;
  242.   }
  243.   /* Now we have to do it the hard way */
  244.   /* We will add this later; before release!!! */
  245. }
  246.  
  247. void spltext(msgfrom,id,system,text,privmsg)
  248. int msgfrom, id, privmsg;
  249. char *system, *text;
  250. {
  251.   char tempstring[64];
  252.   char outbuf[512];
  253.   int x, y;
  254.   char *textptr;
  255.  
  256.   if (!validjob(id))
  257.     return;
  258.   if (job[id].termtype[0]==0)
  259.     return;
  260.  
  261.   if (msgfrom>=0)
  262.   {
  263.     outbuf[0]=0;
  264.     if (msgcount>99)
  265.       msgcount=0;
  266.     if ((job[id].showcount)&&(!privmsg))
  267.       sprintf (outbuf,"[%02d]",msgcount);
  268.     strcat (outbuf,system);
  269.     if (job[id].showjob)
  270.     {
  271.       sprintf (tempstring,"%d-",msgfrom);
  272.       strcat (outbuf,tempstring);
  273.     }
  274.     if (!job[id].padname)
  275.       strcat (outbuf,job[msgfrom].name);
  276.     else
  277.     {
  278.       sprintf (tempstring,"%-10s",job[msgfrom].name);
  279.       strcat (outbuf,tempstring);
  280.     }
  281.     strcat (outbuf,"> ");
  282.     strcat (outbuf,text);
  283.   }
  284.   else
  285.     sprintf (outbuf,"%s %s",system,text);
  286.   wwrap (outbuf);
  287.   spltxout (id,outbuf);
  288.   x=strlen(job[id].buf);
  289.   y=job[id].li-3;
  290.   while (x>=80)
  291.   {
  292.     x-=80;
  293.     y++;
  294.   }
  295.   textptr=tgoto(job[id].cm,x,y);
  296.   write (job[id].fd,textptr,strlen(textptr));
  297. }
  298.  
  299. void splredraw(id)
  300. int id;
  301. {
  302.   char *textptr, message[256];
  303.  
  304.   textptr=tgoto(job[id].cm,0,job[id].li-4);
  305.   sprintf (message, "%s%s%s MCM Split-Screen mode (TERMCAP)  --- /T alone to return to normal mode %s\n\r",
  306.        job[id].cl,textptr,job[id].so,job[id].se);
  307.   write (job[id].fd,message,strlen(message));
  308.   strcpy (message,tgoto(job[id].cm,0,job[id].li-3));
  309.   write (job[id].fd,message,strlen(message));
  310.   splnewinp(id);
  311.   write (job[id].fd,job[id].buf,strlen(job[id].buf));
  312.   return;
  313. }
  314.  
  315. /* For some reason, ANSI won't let the old K&R stuff work here... */
  316. #ifdef NOANSI
  317. void splchar(id,text)
  318. int id;
  319. char text;
  320. #else
  321. void splchar(int id, char text)
  322. #endif
  323. {
  324.   write (job[id].fd,&text,1);
  325. }
  326.  
  327. void splbackup(id)
  328. int id;
  329. {
  330.   write (job[id].fd,"\b \b",3);
  331. }
  332.  
  333. void splnewinp(id)
  334. int id;
  335. {
  336.   char outbuf[256];
  337.   int i;
  338.  
  339.   if (!validjob(id))
  340.     return;
  341.  
  342.   if (job[id].termtype[0]==0)
  343.     return;
  344.  
  345.   for (i=job[id].li;i>=job[id].li-3;i--)
  346.   {
  347.     sprintf (outbuf,"%s%s",tgoto(job[id].cm,0,i),job[id].ce);
  348.     write (job[id].fd,outbuf,strlen(outbuf));
  349.   }
  350. }
  351.  
  352. void set_lines (id,lines)
  353. int id, lines;
  354. {
  355.   if ((lines<8)||(lines>99))
  356.     return;
  357.   if (!validjob(id))
  358.     return;
  359.   if (job[id].termtype[0]==0)
  360.     return;
  361.  
  362.   job[id].li=lines;
  363.   splredraw(id);
  364.   tell (-1,id,"(sys)","Lines per page changed.");
  365. }
  366.  
  367. #endif /* TERMCAP */
  368.